{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Install spaCy and download the 'en_core_web_md' model\n",
    "!pip install spacy\n",
    "!python -m spacy download en_core_web_md\n",
    "\n",
    "# Import libraries\n",
    "import spacy\n",
    "import numpy as np\n",
    "from scipy.spatial.distance import cosine, euclidean\n",
    "\n",
    "# Load the pre-trained word embeddings model\n",
    "nlp = spacy.load('en_core_web_md')\n",
    "\n",
    "# Define the texts\n",
    "text_a = \"The cat is playing with a toy.\"\n",
    "text_b = \"A kitten is interacting with a plaything.\"\n",
    "text_c = \"The chef is cooking a delicious meal.\"\n",
    "text_d = \"Economics is the social science that studies the production, distribution, and consumption of goods and services.\"\n",
    "text_e = \"Economics studies goods and services.\"\n",
    "\n",
    "# Convert the texts to vector representations using the spaCy model\n",
    "vector_a = nlp(text_a).vector\n",
    "vector_b = nlp(text_b).vector\n",
    "vector_c = nlp(text_c).vector\n",
    "vector_d = nlp(text_d).vector\n",
    "vector_e = nlp(text_e).vector\n",
    "\n",
    "# Calculate the cosine similarity between the vectors\n",
    "cosine_sim_ab = 1 - cosine(vector_a, vector_b)\n",
    "cosine_sim_ac = 1 - cosine(vector_a, vector_c)\n",
    "cosine_sim_de = 1 - cosine(vector_d, vector_e)\n",
    "\n",
    "print(f\"Cosine similarity between Text A and Text B: {cosine_sim_ab:.2f}\")\n",
    "print(f\"Cosine similarity between Text A and Text C: {cosine_sim_ac:.2f}\")\n",
    "print(f\"Cosine similarity between Text D and Text E: {cosine_sim_de:.2f}\")\n",
    "\n",
    "# Calculate the Euclidean distance between the vectors\n",
    "euclidean_dist_ab = euclidean(vector_a, vector_b)\n",
    "euclidean_dist_ac = euclidean(vector_a, vector_c)\n",
    "euclidean_dist_de = euclidean(vector_d, vector_e)\n",
    "\n",
    "print(f\"Euclidean distance between Text A and Text B: {euclidean_dist_ab:.2f}\")\n",
    "print(f\"Euclidean distance between Text A and Text C: {euclidean_dist_ac:.2f}\")\n",
    "print(f\"Euclidean distance between Text D and Text E: {euclidean_dist_de:.2f}\")\n",
    "\n",
    "# Calculate the magnitudes of the vectors\n",
    "magnitude_d = np.linalg.norm(vector_d)\n",
    "magnitude_e = np.linalg.norm(vector_e)\n",
    "\n",
    "print(f\"Magnitude of Text D's vector: {magnitude_d:.2f}\")\n",
    "print(f\"Magnitude of Text E's vector: {magnitude_e:.2f}\")\n"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
